package com.zyl.demo.mapper;

import com.zyl.demo.beans.Commodity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommodityMapper {

    @Select("select * from t_commodity ")
    List<Commodity> getAllCommodity();

//    @Insert("insert into t_commodity (commodity_name,commodity_describe,commodity_img_small,commodity_img_medium,commodity_img_big,commodity_img_1,commodity_img_2,commodity_img_3,commodity_img_4,commodity_img_details_1,commodity_img_details_2,commodity_img_details_3,commodity_img_details_4,commodity_original_price,commodity_discount_price,category_id,category_sub_id) values (#{commodityName},#{commodityDescribe},#{commodityImgSmall},#{commodityImgMedium},#{commodityImgBig},#{commodityImg1},#{commodityImg2},#{commodityImg3},#{commodityImg4},#{commodityImgDetails1},#{commodityImgDetails2},#{commodityImgDetails3},#{commodityImgDetails4},#{commodityImgOriginalPrice},#{commodityDiscountPrice},#{categoryId},#{categorySubId})")
//    int addCommodity(Commodity commodity);\

    @Select("select * from t_commodity where commodity_id = #{commodityId}")
    Commodity getCommodityById(int commodityId);

    @Delete("delete from t_commodity where commodity_id = #{commodityId}")
    int deleteCommodity(int commodityId);

    @Select("SELECT * FROM t_commodity ORDER BY commodity_create_time DESC LIMIT 0,10")
    List<Commodity> getRecommendList();//推荐商品 按时间来 前10个

    @Select("SELECT * FROM t_commodity where category_id=#{categoryId} LIMIT 0,5")
    List<Commodity> getCommodityByCategoryIdFive(int categoryId);

    @Select("SELECT * FROM t_commodity LIMIT #{startPage},#{step}")
    List<Commodity> getCommodityPage(int startPage, int step);

    @Select("SELECT * FROM t_commodity where category_id=#{categoryId} LIMIT #{page},#{step}")
    List<Commodity> getCommodityByCategoryId(int categoryId,int page,int step);

    @Select("SELECT * FROM t_commodity where category_id=#{categoryId} and category_sub_id=#{categorySubId} LIMIT #{page},#{step}")
    List<Commodity> getCommodityByCategoryIdAndCategorySubId(int categoryId,int categorySubId,int page,int step);
}
